<include file="Public/_meta" />

<title>添加用户</title>
<link rel="stylesheet" href="http://www.jq22.com/jquery/bootstrap-3.3.4.css">
  <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-select/dist/css/bootstrap-select.css">
  <script type="text/javascript" src="__PUBLIC__/lib/jquery/1.9.1/jquery.min.js"></script>
  <script src="http://www.jq22.com/jquery/bootstrap-3.3.4.js"></script>
  <script src="__PUBLIC__/css/bootstrap-select/dist/js/bootstrap-select.js"></script>
</head>
<body>
<article class="page-container">
	<form action='' method="post" class="form form-horizontal" id="form-member-alert">
		<div class="row cl">
			<input name="userid" type="hidden" value="{$user.user_id}"/>
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$user.user_name}" placeholder=""  name="username">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">电话：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$user.phone}" placeholder=""  name="telphone">
			</div>
		</div>

        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>OA权限：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select class="select" size="1" name="oaLevel">
					<option value="0" <eq name="user.oa_level" value="0">selected</eq> >无</option>
					<option value="1" <eq name="user.oa_level" value="1">selected</eq> >普通销售员</option>
					<option value="2" <eq name="user.oa_level" value="2">selected</eq> >销售经理</option>
					<option value="3" <eq name="user.oa_level" value="3">selected</eq> >总经理</option>
					<option value="4" <eq name="user.oa_level" value="4">selected</eq> >管理员</option>
				</select>
				</span> </div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属区域：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select class="select select-place" size="1" name="place">
					<option value="" selected>请所属区域</option>
					<volist name="place" id="val">
						<option value="{$key}" <if condition="$key eq $user['place']">selected</if>>{$val}</option>
					</volist>
				</select>
				</span> </div>
		</div>

        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select class="select role select-zong" size="1" name="role">
					<option value="{$user.level}" selected>{$user.level|returnRole}</option>
				</select>
				</span> </div>
		</div>
		<div class="row cl skin-minimal shenhe" style="display:none">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>负责的银行：</label>
			<select id="first-disabled2" class="selectpicker" multiple data-hide-disabled="true" data-size="5" name="bank[]">
					<option value="" >请选择银行</option>
					<volist name="banks" id="ba">
						<option value="{$ba.bank_id}" <in name="ba.bank_id" value="$user.bank_id">selected</in>>{$ba.bank_name}</option>
					</volist>
				</select>
  			</div>
		</volist>
		</div>

		<div class="row cl" >
			<label class="form-label col-xs-4 col-sm-3">直属上级：</label>
				<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select class="select select-zhi" size="1" name="leader">
					<option value="{$user.leader}" selected>{$user.leader|getUsername}</option>
				</select>
				</span> </div>
		</div>

		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
<script type="text/javascript" src="__PUBLIC__/lib/layer/2.1/layer.js"></script>

<script type="text/javascript">
$('.select-place').change(function(){
    var place = $(this).val();
    $('.select-zong').empty();
    $('.select-zong').append('<option value="">请选择角色</option>')
    if(place=='1'){
        $('.select-zong').append("<option value='1'>营销人</option><option value='2'>签单人</option><option value='3'>审核人</option><option value='4'>管理员（总经理）</option><option value='12'>总经理</option><option value='10'>副总经理</option><option value='8'>收费人</option><option value='9'>消费部门</option><option value='15'>市区公积金审核</option><option value='16'>抵押他证审核人</option><option value='17'>银行驻场</option>");
    }
    else if(place=='2'){
        $('.select-zong').append("<option value='1'>营销人</option><option value='6'>江宁签单审核人</option><option value='13'>江宁负责人</option><option value='16'>抵押他证审核人</option>");
    }
    else{
        $('.select-zong').append("<option value='1'>营销人</option><option value='11'>江北签单审核</option><option value='14'>江北负责人</option><option value='16'>抵押他证审核人</option>");
    }
})

$('.select-zong').change(function(){
    var len=$('.select-zong option').length;
    var place = $('select[name="place"]').val();
    for(i = 0;i < len;i++){
        if($('.select-zong option').eq(i).is(':selected')){
            var id=$('.select-zong option').eq(i).val();
        }
    }
    $.ajax({
        type:'post',
        url:"{:U('User/zhi')}",
        data:{id:id,place:place},
        dataType:'json',
        success:function(json){
            console.log(json);
            $('.select-zhi').empty();
            $('.select-zhi').append('<option value="">请选择上级</option>')
            var len=json.length;
            for(i = 0;i <= len;i++){
                $('.select-zhi').append('<option value='+json[i]['user_id']+'>'+json[i]['user_name']+'</option>')
            }
        }
    })
})
var index = parent.layer.getFrameIndex(window.name)
$("#form-member-alert").submit(function(){
  $(".radius").attr('type','button');
        $.ajax({
          url:'{:U("User/editCheck")}',
          type:'post',
          data:$("#form-member-alert").serialize(),
          dataType:'json',
          success:function(data){
            if(data.ResultCode == '200'){
              layer.msg(data.ResultMessage,{time:1000},function(){
                  parent.window.location.reload()
                  parent.layer.close(index);
              });
            }
            else if(data.ResultCode == '500'){
                layer.msg(data.ResultMessage,{time:1000},function(){

                })
            }
          }
        })
        return false;
	});

	$(function(){
		$('.skin-minimal input').iCheck({
			checkboxClass: 'icheckbox-blue',
			radioClass: 'iradio-blue',
			increaseArea: '20%'
		});
	});
    var val = $('.role').val();
	   if(val == 3 || val == 7 || val == 11){
	       $('.role').parents('.cl').next().css('display','block')
	   }else{
	       $('.role').parents('.cl').next().css('display','none')
	   }
	$('.role').change(function(){
	   var val = $(this).val();
	   if(val == 3 || val == 7 || val == 11 || val==17){
	       $(this).parents('.cl').next().css('display','block')
	   }else{
	       $(this).parents('.cl').next().css('display','none')
	   }
	})
</script>
</body>
</html>
